<?
header ("content-type: text/html; charset=utf-8");
session_start();

//ini_set("error_reporting","E_ALL & ~E_NOTICE & ~E_STRICT");
$admin_area=1;
$admin = 1;
$req_level=1;

if (!isset($_SESSION["admin"]))
{
	$host  = $_SERVER['HTTP_HOST'];
	$uri  = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
	$extra = 'login.php';
	header("Location: http://$host$uri/$extra");
	exit;
}
else 
{
	require("../includes/common_admin_inc.php");
	if (isset($lUseAjax)) // If Ajax enabled for this page
		include "../includes/ajaxfunctions.php";
	$set_template_dir="templates_new";
	
	if ($set_level_permissions)
	{
		$lCurrentPage = $_SERVER["SCRIPT_NAME"]; 
		$lCurrentPage=split("/",$lCurrentPage);
		$lCurrentPage=end($lCurrentPage);
		
		function getPermLevel($aPage)
		{
			
			global $set_level_perm_level1,$set_level_perm_level2,$set_level_perm_level3;
			
			$lFileArray_level1=split(",",$set_level_perm_level1);
			if (in_array($aPage,$lFileArray_level1))
				return 1;
			$lFileArray_level2=split(",",$set_level_perm_level2);
			if (in_array($aPage,$lFileArray_level2))
				return 2;
			$lFileArray_level3=split(",",$set_level_perm_level3);
			if (in_array($aPage,$lFileArray_level3))
				return 3;
		}
		
		$req_level=getPermLevel($lCurrentPage);
		
		if ($_SESSION["admin_level"]>$req_level AND isset($req_level))
		{
			echo "You do not have enough permissions to access this.<br />";
			echo "You have access level " . $_SESSION["admin_level"] . ", but this page requires level " . $req_level . ".";
			
			echo "<p><a href='index.php'>Return to main admin area</a></p>";
			exit;
		}
	}
}

if (getParam("logout",""))
{
	session_destroy();
	redirect("login.php");
}

if (isset($lIsMod))
	$lAddPath="../../";

$tplHeader = new tplLoad();

$lCurrentPageArray=split("\/",$_SERVER['PHP_SELF']);
$lCurrentPage=end($lCurrentPageArray);

$lArray=array(
'index.php' => LA_ADMIN_MENU1_MAIN,
'adm_user_list.php' => LA_ADMIN_MENU1_USERS,
'adm_classifieds_list.php' => LA_ADMIN_MENU1_CLASSIFIEDS,
'adm_classifieds_list.php?validated=2' => LA_ADMIN_MENU1_VALADS,
'adm_user_list.php?validated=2' => LA_ADMIN_MENU1_VALUSR,
'adm_comments.php' => LA_ADMIN_MENU1_COMMENTS,
'adm_categories.php' => LA_ADMIN_MENU1_CATEGORIES,
'adm_newsletter2.php' => LA_ADMIN_MENU1_EMAILMEMBERS,
'adm_advertiser.php' => LA_ADMIN_MENU1_BANNERMNGR,
'adm_visitor_stat.php' => LA_ADMIN_MENU1_VISITORSTATS,
'adm_block.php' => LA_ADMIN_MENU1_BLOCKUSERS,
'adm_orders.php' => LA_ADMIN_MENU1_ORDERS,
'adm_content_stat.php' => LA_ADMIN_MENU1_ADSTAT,
'adm_history.php' => LA_ADMIN_MENU1_ACTIVITY,
'adm_logviewer.php' => LA_ADMIN_MENU1_LOGVIEWER,
'adm_backup.php' => LA_ADMIN_MENU1_BACKUP,
'../' => LA_ADMIN_MENU1_FRONTPAGE,
);

foreach ($lArray as $key => $value) {

	$lStop=0;
	if (eregi($lCurrentPage,$key))
	{
		if ($key=="adm_classifieds_list.php?validated=2")
		{
			if (getParam("validated","")!=2)
				$lStop=1;
		}
		if ($key=="adm_classifieds_list.php")
		{
			if (getParam("validated","")==2)
				$lStop=1;
		}
		if ($key=="adm_user_list.php?validated=2")
		{
			if (getParam("validated","")!=2)
				$lStop=1;
		}
		if ($key=="adm_user_list.php")
		{
			if (getParam("validated","")==2)
				$lStop=1;
		}
		
		if (!$lStop)
			$value="<b>$value</b>";
	}	
	$lNewArray_1[]=array($lAddPath.$key => $value);

}


$lArray=array(
'adm_set.php?file=gen_inc.php' => LA_ADMIN_MENU2_GEN,
'adm_set.php?file=opt_inc.php' => LA_ADMIN_MENU2_OPT,
'adm_set.php?file=pay_inc.php' => LA_ADMIN_MENU2_PAY,
'adm_fields.php' => LA_ADMIN_MENU2_EXTRAFIELDS,
'adm_extra.php' => LA_ADMIN_MENU2_FIELD_TEMPLATE,
'adm_regions.php' =>LA_ADMIN_MENU2_REGIONS,
'adm_html_edit.php' => LA_ADMIN_MENU2_HTML_TEMPLATES,
'adm_package_edit.php' => LA_ADMIN_MENU2_PAY_PACKAGES,
'adm_lang_editor.php' => LA_ADMIN_MENU2_LANG_EDITOR,
'adm_maileditor.php' => LA_ADMIN_MENU2_MAIL_EDITOR,
'adm_language_files.php' => LA_ADMIN_MENU2_LANG_FILES,
'adm_fill_db.php' => LA_ADMIN_MENU2_MAKE_DEMO,
'adm_imagestatus.php' => LA_ADMIN_MENU2_IMG_STATUS,
'adm_users.php' => LA_ADMIN_MENU2_ADMINS,
);


foreach ($lArray as $key => $value) {
$lStop=0;
	if (eregi($lCurrentPage,$key))
	{
		if ($lCurrentPage=="adm_set.php")
		{
			if (getParam("file","")!="gen_inc.php" && $key=="adm_set.php?file=gen_inc.php")
				$lStop=1;
			if (getParam("file","")!="opt_inc.php" && $key=="adm_set.php?file=opt_inc.php")
				$lStop=1;
			if (getParam("file","")!="pay_inc.php" && $key=="adm_set.php?file=pay_inc.php")
				$lStop=1;
			if (getParam("file","")!="board_inc.php" && $key=="adm_set.php?file=board_inc.php")
				$lStop=1;
				
		}
		
		if (!$lStop)
			$value="<b>$value</b>";
			
			
	}	
	$lNewArray_2[]=array($lAddPath.$key => $value);

}



// Support for mods
function getMods()
{
	global $lAddPath,$lIsMod;
	
	if (isset($lIsMod))
		$dir = opendir("../../mods/");
	else 
		$dir = opendir("mods/");
		$i=0;
	while ($file = readdir($dir))
  	{
		if ($file <> "." AND $file <> "..")
        {
		  	$lDir=$file;
		 	$lDirUpper=ucfirst($lDir);
		  	
		  	$lArray["mods/$lDir"]=$lDirUpper;
		  	$i++;
		}
  	}
  	closedir($dir);
	return $lArray;
}

$lArray=getMods();
$lSize=sizeof($lArray);

if ($lSize>0)
{
	foreach ($lArray as $key => $value) 
	{
		$lStop=0;
		if (eregi($lCurrentPage,$key))
			$value="<b>$value</b>";

		$lNewArray_3[]=array($lAddPath.$key => $value);

	}

	$tplHeader->assign('menu_list_3', $lNewArray_3);
	
}
// END support

$tplHeader->assign('menu_list_1', $lNewArray_1);
$tplHeader->assign('menu_list_2', $lNewArray_2);
$tplHeader->assign('adm_name', $_SESSION["admin_name"]);
$tplHeader->assign('adm_level', $_SESSION["admin_level"]);
$tplHeader->assign('set_fill_db', $set_fill_db);
$tplHeader->assign("url",$set_url);
$tplHeader->assign("charset",$set_charset);
$tplHeader->assign("html_editor",$set_wysiwyg_editor);

$tplHeader->display("adm_header.tpl");
?>